#Author: Tanyong
# *-* coding:utf8 *-*
# @time       : 2018/7/20 21:02
# @Author     : Tanyong
# @Site       : 
# @File       : common.py
# @Software   : PyCharm

# 所有自定义的工具类


# 使用装饰器的形式 去查询用户的登录信息
import functools
from flask import current_app
from flask import g
from flask import session

def user_login_data(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        user_id = session.get('user_id')
        user = None
        if user_id:
            try:
                from info.models import User
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)

        g.user = user
        return func(*args, **kwargs)
    return wrapper


# 自定义过滤器
def do_index_class(index):
    if index == 1:
        return "first"
    elif index == 2:
        return "second"
    elif index == 3:
        return "third"
    return ""